(function(S) {

	S.declare('Tip', S.Widget, {
		type : '',
		content : '',
		className : 'simple-tip',
		position : null,
		timeout : 3000,
		templateString : '<span class="simple-tip-icon"></span><div rel="tipcontent"></div>',
		init : function() {
			this.container.append(this.templateString);
			this.node = this.container;
			this.tipContent = this.container.find('[rel=tipcontent]');
		},
		renderUI : function() {
			var tipTypeCls;
			switch(this.type) {
				case "load":
					tipTypeCls = "simple-tip-load";
					break;
				case "success":
					tipTypeCls = "simple-tip-success";
					break;
				case "info":
					tipTypeCls = "simple-tip-info";
					break;
				case "alert":
					tipTypeCls = "simple-tip-alert";
					break;
			}
			this.container.addClass(tipTypeCls);
			this.setContent(this.content);
			this.setPosition(this.position);
		},
		bindUI : function() {
			var self = this, hideTimeout

			if (this.type != 'load') {
				hideTimeout = setTimeout(function() {
					self.destroy();
				}, this.timeout);

				this.container.bind({
					'mouseover' : function() {
						clearTimeout(hideTimeout);
					},
					'mouseout' : function() {
						hideTimeout = setTimeout(function() {
							self.destroy();
						}, self.timeout);
					}
				});
			}
		},
		setContent : function(content) {
			this.tipContent.html(content);
		},
		destroy : function() {
			this.container.unbind();
			this.inherit(arguments);
		}
	});
	
	S.each(['success,alert,,info,load'],function(item){
		jQuery[item+'Tip'] = function(content,timeout){
			return new S.Tip({
				content:content,
				type:item,
				timeout:timeout
			});
		}
	});
	
})(Simple);
